package tools.math;

import java.util.LinkedList;

public class Math_ {

	public static final boolean DEBUG = false;
	
	public static double mean(LinkedList<Double> list) {
		double sum = 0;
		for(Double d : list)
			sum += d;
		
		if(DEBUG) {
			System.out.println("Elements "+list.size());
			for(Double d : list)
				System.out.print(d+" ");
			System.out.println("\nMean "+sum/list.size());
		}
		
		return sum/list.size();
	}
	
	public static int safeLongToInt(long l) {
	    int i = (int)l;
	    if ((long)i != l) {
	        throw new IllegalArgumentException(l + " cannot be cast to int without changing its value.");
	    }
	    return i;
	}
	
}
